import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity,
} from 'react-native';
/**
 * 由 WangYu 创建
 * 日期 2017/9/28
 */
export default class CommonUtil extends Component {

    constructor(props) {
        super(props);
    }

    /**
     * 格式化money
     * s为要格式化的money
     * n为小数位数
     */
   static fmoney(s, n){
        if(s==='')
            return;
        n = n > 0 && n <= 20 ? n : 2;
        s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
        var l = s.split(".")[0].split("").reverse(),
            r = s.split(".")[1];
        var t = "";
        for(let i = 0; i < l.length; i ++ ) {
            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
        }
        return t.split("").reverse().join("") + "." + r;
    }
    /**
     * 获取当前系统时间 yyyyMMddHHmmss
     */
    static getCurrentDate() {
        var space = "";
        var dates = new Date();
        var years = dates.getFullYear();
        var months = dates.getMonth() + 1;
        if (months < 10) {
            months = "0" + months;
        }

        var days = dates.getDate();
        if (days < 10) {
            days = "0" + days;
        }

        var hours = dates.getHours();
        if (hours < 10) {
            hours = "0" + hours;
        }

        var mins = dates.getMinutes();
        if (mins < 10) {
            mins = "0" + mins;
        }

        var secs = dates.getSeconds();
        if (secs < 10) {
            secs = "0" + secs;
        }
        var time = years + space + months + space + days + space + hours + space + mins + space + secs;
        return time;
    };

    /**
     * 获取当前系统时间 yyyyMMddHH
     */
    static getCurrentDateFormat() {
        var space = "";
        var dates = new Date();
        var years = dates.getFullYear();
        var months = dates.getMonth() + 1;
        if (months < 10) {
            months = "0" + months;
        }

        var days = dates.getDate();
        if (days < 10) {
            days = "0" + days;
        }
        var time = years + space + months + space + days;
        return time;
    };
}

